/**
 * Project: complex.java
 * 
 * File Created at 2011-9-8
 * $Id$
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package complex.java.serialize;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * java序列化反序列化
 * 
 * @author ymkyve
 */
public class JavaSerializable implements ISerializable {
	@Override
	public void serialize(Order order) throws Exception {
		System.out
				.println("=================JavaSerializable============================");
		long start = System.currentTimeMillis();
		// 序列化
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		ObjectOutputStream objectOutput = new ObjectOutputStream(output);
		objectOutput.writeObject(order);
		objectOutput.flush();
		long serialize = System.currentTimeMillis();
		// 反序列化
		ByteArrayInputStream input = new ByteArrayInputStream(
				output.toByteArray());
		ObjectInputStream objectInput = new ObjectInputStream(input);
		Order order1 = (Order) objectInput.readObject();
		long deSerialize = System.currentTimeMillis();
		// System.out.println(order1);
		System.out.println("serialize:" + (serialize - start));
		System.out.println("deSerialize:" + (deSerialize - serialize));
	}

}
